package com;

/**
 * 暂停线程
 * 线程中可以使用suspend()暂停线程
 * 使用resume()回复线程
 */

/**
 * 使用
 */
class Thread01 extends Thread {
    private long i = 0;

    public void setI(long i) {
        this.i = i;
    }

    public long getI() {
        return this.i;
    }

    @Override
    public void run() {
        super.run();
        while (true) {
            i++;
        }
    }
}

public class Demo08 {
    public static void main(String[] args) {
        try {
            Thread01 thread = new Thread01();
            thread.start();
            Thread.sleep(5000);
            thread.suspend();
            System.out.println("systemA:" + System.currentTimeMillis() + "--i:" + thread.getI());
            Thread.sleep(5000);
            System.out.println("systemA:" + System.currentTimeMillis() + "--i:" + thread.getI());

            thread.resume();
            Thread.sleep(5000);

            thread.suspend();
            System.out.println("systemB:" + System.currentTimeMillis() + "--i:" + thread.getI());
            Thread.sleep(5000);
            System.out.println("systemB:" + System.currentTimeMillis() + "--i:" + thread.getI());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
